/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var context;
//function OnButtonSearchClicked(path){
//    //  var str = searchBox.value.trim().VNize().removeAccent().toUpperCase();
//    context = path;
//    var url="action=search&query=";
//    url += removeWhitespace(query.trim());
//
//    SendXMLHttpRequestUrl("AjaxSearchServlet", url);
////alert(url);
//}
//
//function OnReadyStateChangeHandler(xmlHttp){
//    if(xmlHttp.state == 4 && xmlHttp.status == 200){
//        var xml = xmlHttp.responseXML;
//
//        var xsl = loadXMLDoc("${pageContext.request.contextPath}/xsl/TestSongXSL.xsl");
//
//        if(xml.parseError.errorCode!=0){
//            alert("Error xml: "+xml.parseError.reason);
//        }else if(xml.parseError.errorCode!=0){
//            alert("Error xslt: "+xsl.parseError.reason);
//        }else{
//            var out = xml.transformNode(xsl);
//            document.getElementById('search_result').innerHTML=out;
//        }
//    }
//}

function OnButtonSearchClicked(path){

    context = path;
    var xmlHttp = getXMLHttpRequest();
    var url = "action=search&query=";
    url+= removeWhitespace(query.trim());

    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4 && xmlHttp.status==200)
        {
            var xml = xmlHttp.responseXML;
            var xsl = loadXMLDoc(context+"/xsl/TestSongXSL.xsl");

            xsltProcessor=new XSLTProcessor();
            xsltProcessor.importStylesheet(xsl);
            resultDocument = xsltProcessor.transformToFragment(xml,document);
            document.getElementById("search_result").appendChild(resultDocument);
        } // end if
    } // end function

    xmlHttp.open("GET","AjaxSearchServlet?action=search&query="+query.trim(),true);
    // xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send();
}